#!/bin/bash
#2020/4/5
#by wd

function Apache2()
{
	yum -y update
	yum -y install httpd
	systemctl enable httpd
	systemctl start httpd
	firewall-cmd --permanent --zone=public --add-service=http --permanent
	firewall-cmd --permanent --zone=public --add-service=https --permanent
	firewall-cmd --reload
	systemctl status httpd
	httpd -v
}

function kodexplorer()
{
	cd /var/www/html/
	yum -y install wget
	wget http://static.kodcloud.com/update/download/kodexplorer4.40.zip
	unzip kodexplorer4.40.zip -d /var/www/html/kodexplorer
	su -c 'setenforce 0'
	chmod -R 777 /var/www/html/kodexplorer/
	rm -rf /var/www/html/kodexplorer4.40.zip
	echo -e "\033[32mopen http://IP/kodexplorer\033[0m"	
}

function PHP()
{
	rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
	rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
	yum -y install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath
	yum -y install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath
	service php-fpm start
}

function All()
{
	yum update
	yum install httpd
	systemctl enable httpd
	systemctl start httpd
	firewall-cmd --permanent --zone=public --add-service=http
	firewall-cmd --permanent --zone=public --add-service=https
	firewall-cmd --reload
	rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
	rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
	yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath
	yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath
	service php-fpm start
	systemctl restart httpd
	cd /var/www/html/
	yum -y install wget
	wget http://static.kodcloud.com/update/download/kodexplorer4.40.zip
	unzip kodexplorer4.40.zip -d /var/www/html/kodexplorer
	su -c 'setenforce 0'
	chmod -R 777 /var/www/html/kodexplorer/
	rm -rf /var/www/html/kodexplorer4.40.zip
	sed -i '119s/\/var\/www\/html/\/var\/www\/kodexplorer/g' /etc/httpd/conf/httpd.conf
	systemctl restart httpd
	echo -e "\033[32mopen http://IP\033[0m"	
}

function Menu()
{
	echo -e "\033[32mPlease enter the service you want \033[0m"	
	echo "1)Apache2"
	echo "2)kodexplorer"
	echo "3)PHP7.1"
	echo "4)All"	
	echo "5)Exit"	
}

if [[ $UID -ne 0 || $uid -ne 0 ]];then
	echo  -e "\033[36mPlease Run the $0 under root\033[0m"
	exit
fi

echo -e "\033[32mPlease select the service to install \033[0m"

#PS3作为select语句的shell界面提示符，提示符为PS3的值（赋予的字符串），更换默认的提示符#?
PS3="select your will exec Menu(1|2|3|4|5):"

select i in "Apache2" "kodexplorer" "PHP7.1" "All" "Exit"

do

case $i in
	Apache2 )
	echo -e "\033[32mwait insatll httpd server....\033[0m"
	Apache2
	Menu
	;;
	PHP7.1 )
	echo -e "\033[32mwait install PHP7.1 ....\033[0m"
	PHP
	Menu
	;;
	kodexplorer)	
	echo -e "\033[32mwait install kodexplorer....\033[0m"
	kodexplorer
	Menu
	;;
	All )
	echo -e "\033[32mAll waiting to be installed\033[0m"
	All
	Menu
	;;
	Exit )
	exit
	;;

#输入其他值
	* )
	echo -e "\033[32mUsage: {$0 Apache|kodexplorer|PHP} \033[0m"
	;;
esac

done
